#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   文件名称 :     __init__.py
   文件功能描述 :   功能描述
   创建人 :       小钟同学
   创建时间 :          2021/12/6
-------------------------------------------------
   修改描述-2021/12/6:         
-------------------------------------------------
"""
from grpcframe.zyxgrpc.base_middleware import BaseMiddleware
from typing import Any
from grpc_interceptor.exceptions import GrpcException
from grpcframe.zyxgrpc.globals import set_current_app_context,set_current_app_request,set_current_app_request_context
from grpcframe.exts.grpclocal.request import Request
import grpc

# @app.add_middleware
class GrequestMiddleware(BaseMiddleware):

    def before_handler(self, request: Any, context: grpc.ServicerContext, method_name):
        pass
        # 设置上下文信息处理
        set_current_app_context(context)
        set_current_app_request(request)
        set_current_app_request_context(Request(request=request,context=context))
        # 创建类似flask的上下文的对象
    def after_handler(self, context: grpc.ServicerContext, response):
        pass

    def error_grpc_exc_handler(self,e:GrpcException):
        pass

    def finally_handler(self):
        pass
